fix(graphql-codegen-client-preset): handle Windows-style paths in WASM runtime#595
Conversation
…M runtime The SWC plugin runs inside a WASM runtime which always uses Unix path semantics, but on Windows the host passes paths with backslashes (e.g. C:\Users\user\project\src\gql). PathBuf in WASM does not treat backslashes as separators, so path computation was silently wrong and produced invalid relative import paths. Fix by: 1. Normalizing all input paths (cwd, filename, artifactDirectory) by replacing backslashes with forward slashes before any PathBuf usage. 2. Replacing the Path::is_absolute() check with an explicit helper that also recognises Windows drive-letter paths (C:/...) as absolute, since Path::is_absolute() returns false for those under WASM/Unix semantics. Fixes #524 Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
|
|
|
PR Review: fix(graphql-codegen-client-preset): handle Windows-style paths in WASM runtimeThe fix is correct and well-reasoned. The root cause (WASM always using Unix path semantics while the host provides Windows paths) is clearly explained, and both normalization steps are necessary. Positive aspects
IssuesMinor: redundant In let resolved_artifact_directory = if is_absolute_path(&artifact_directory) {
artifact_directory.to_string() // artifact_directory is already a String
let resolved_artifact_directory = if is_absolute_path(&artifact_directory) {
artifact_directory
} else {
let mut cwd_path = PathBuf::from(&cwd);
cwd_path.push(&artifact_directory);
cwd_path.to_string_lossy().into_owned()
};Suggestion: add a test for relative Windows paths The new test covers Windows absolute paths ( Out of scope / known limitation: UNC paths Windows UNC paths ( Overall this is a solid, focused fix. Addressing the redundant |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6649bbfad2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut file_full_path = PathBuf::from(&cwd); | ||
| file_full_path.push(&filename); |
There was a problem hiding this comment.
Treat absolute Windows filenames before joining with cwd
When filename comes from SWC as an absolute Windows path (for example C:\repo\src\App.tsx), PathBuf::push here still appends it under cwd because the WASM runtime is using Unix path semantics and does not recognize C:/... as absolute. That makes file_s_dirname become something like C:/repo/C:/repo/src, so diff_paths generates imports such as ./../../../../../src/gql/graphql instead of ./gql/graphql. The new test only covers a relative filename, so this case stays broken for hosts that provide absolute filenames.
Useful? React with 👍 / 👎.
|
@claude fix ci |
|
Claude finished @kdy1's task in 3m 28s —— View job CI Fixed
The CI failure was a merge conflict in test code — main added a |
…path test The naming_convention field was added to GraphQLCodegenOptions in main but the new get_windows_path_visitor test function introduced by this PR didn't include it, causing a compile error in the CI merge commit. Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
## Summary - Addressed `chatgpt-codex-connector[bot]` review follow-ups across merged PRs: #585, #591, #592, #593, #594, #595, #597, #598, #599. - Applied the fixes as 9 separate commits (one commit per original PR) in a single follow-up branch. ## What Changed - #585 / #592 (`loadable-components`) - Fixed source-less default-import matching to honor the configured local name. - Updated `ssr: false` detection to respect final object-literal override order. - Added/updated fixtures for both behaviors. - #591 / #594 (`formatjs`) - Added JSX member-expression message component support (e.g. `ReactIntl.FormattedMessage`). - Updated #532 regression coverage to validate the `ast: true` path. - #593 / #595 (`graphql-codegen-client-preset`) - Extended `namingConvention` parsing to accept string/object forms. - Preserved names for `keep`/unknown conventions instead of forcing PascalCase. - Fixed Windows absolute `filename` path handling in WASM runtime path resolution. - Added unit coverage for the new config/path behaviors. - #597 / #599 (`emotion`) - Ensured tagged-template labels are terminated before sourcemap comments. - Added css-prop rewrite support for namespace imports (`emotionReact.css`). - Attached PURE comments to the generated call site span. - Updated emotion fixtures accordingly. - #598 (docs) - Corrected capability descriptions in `packages/jest/README.tmpl.md` and `packages/swc-sdk/README.tmpl.md`. ## Validation - `cargo test -p swc_plugin_loadable_components --test fixture -- --ignored` - `cargo test -p swc_plugin_graphql_codegen_client_preset` - `cargo test -p swc_emotion --test fixture -- --ignored` - `pnpm -C /Users/kdy1/.codex/worktrees/17e6/plugins/packages/formatjs test` All passed (formatjs has an existing non-blocking Vitest warning about an un-awaited rejects assertion).
The SWC plugin runs inside a WASM runtime which always uses Unix path semantics, but on Windows the host passes paths with backslashes (e.g.
C:\Users\user\project\src\gql).PathBufin WASM does not treat backslashes as separators, so path computation was silently wrong and produced invalid relative import paths.Fix by:
cwd,filename,artifactDirectory) by replacing backslashes with forward slashes before anyPathBufusage.Path::is_absolute()check with an explicit helper that also recognises Windows drive-letter paths (C:/...) as absolute, sincePath::is_absolute()returns false for those under WASM/Unix semantics.Closes #524
Generated with Claude Code